﻿<!--#include file="conn.asp"#-->
<!--#include file="sessao.asp"#-->
<!--#include file="getsessao.asp"#-->
<!--#include file="fn_multiselect.asp"#-->
<!--#include file="fn_combo.asp"#-->
<!--#include file="fn_table.asp"#-->
<%

Select Case request("acao")
	Case "getTemplate"
		getTemplate()
	Case "getStatus"
		getStatus()		
	Case "getLayout"
		getLayout()				
End Select

Sub getTemplate()
	writeHeader("")

	sql = "SELECT i.titulo      AS Template, "
	sql = sql & "        i.dt_cadastro AS [Data de Cadastro], "
	sql = sql & "        st.desc_status as Status, "
	sql = sql & "        u.nome        AS [Criador], "
	sql = sql & "		'<span class=''info''></span></a> "
	sql = sql & " 		<a href=''#'' class=''botao ico'' onclick=''return getTemplate('+convert(varchar,i.cod_layout_informativos)+');''><span class=''edit''></span></a> ' [Ação]"
	sql = sql & " FROM   informativos.tb_layout_informativos AS i "
	sql = sql & "        INNER JOIN informacao.tb_usuarios AS u "
	sql = sql & "                ON u.cod_usuario = i.cod_usuario_cadastro "
	sql = sql & "        INNER JOIN informativos.tb_status_layout AS st "
	sql = sql & "                ON st.cod_status_layout = i.cod_status_layout "

	sql = sql & " WHERE 1=1 "
	IF request("pesquisa") <> "" THEN
		sql = sql & "       AND i.titulo like '%"&request("pesquisa")&"%' "
	END IF
	sql = sql & " ORDER  BY i.titulo, "
	sql = sql & "           i.dt_cadastro "	

	Dim pg_sel
	if request("pg_sel") = "" then
		pg_sel = 1
	else
		pg_sel = cdbl(request("pg_sel"))
	end if
	response.write Table("listTemplate", sql, "tabela", true, pg_sel, 10,"pesquisaTemplate(!@#)")	

End Sub

Sub getStatus()
	Dim db_string
	db_string = " SELECT * FROM informativos.tb_status_layout ORDER BY desc_status "
	retorno  = fn_combo(db_string,true,"")
	response.write retorno
End Sub

Sub getLayout()
	Dim db_string
	Dim rsLayout
	if request("cod_layout_informativo") <> "" then
		db_string = " select u.cod_status_layout,u.cod_layout_informativos,	u.titulo, replace(u.html,char(10),'') as html"
		db_string = db_string & " from informativos.tb_layout_informativos  as u "
		db_string = db_string & " where u.cod_layout_informativos="&request("cod_layout_informativo")
		set rsLayout = getRs(db_string)
		if not rsLayout.eof then
			retorno = "{success : true, data: {"
			retorno = retorno & "'titulo':'"&rsLayout("titulo")&"',"
			retorno = retorno & "'cod_layout_informativos':'"&rsLayout("cod_layout_informativos")&"',"
			retorno = retorno & "'cod_status_layout':'"&rsLayout("cod_status_layout")&"',"
		    retorno = retorno & "'conteudo':'"&rsLayout("html")&"' }"						
			retorno = retorno & "}"
		End If
		rsLayout.close
	End If
	set rsLayout = nothing
	response.write retorno
End Sub

%>